package memorphic.slide
{
	import flash.display.DisplayObject;
	import flash.events.Event;
	import flash.events.EventDispatcher;
	
	
	/**
	 * A base class to use for Presentation Models.
	 *
	 * It provides <code>[Trigger]</code> metadata for binding to ActionScript properties and functions.
	 * 
	 */	
	public class SlidePresModelBase extends EventDispatcher
	{
		
		
		
		protected var view:IStateView;
		
		private var triggersImpl:TriggerMetadataImpl;

		
		public function SlidePresModelBase(view:IStateView)
		{
			this.view = view;
			triggersImpl = new TriggerMetadataImpl(this);
			
			var v:DisplayObject = view as DisplayObject;

			if(v){
				if(v.root){
					onViewReady(null);
				}else{
					v.addEventListener(Event.ADDED_TO_STAGE, onViewReady);
				}
			}else if(view){
				// it's not a DisplayObject so just assume it's ready
				onViewReady(null);
			}

		}
		
		
		
		private function onViewReady(event:Event):void
		{
			initView();
		}
		
		
		/**
		 * Override this in subclasses
		 * 
		 */
		protected function initView():void
		{
			
		}
		


	}
}